import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/model/home.dart';
import 'package:kxy_flutter_app/view/home/nav_route.dart';

class HomeCateWidget extends StatelessWidget {
  final List<HomeCategory> cateList;

  const HomeCateWidget({Key key, @required this.cateList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 110,
      width: MediaQuery.of(context).size.width,
      margin: EdgeInsets.only(top: 5),
      child: ListView(
        padding: EdgeInsets.symmetric(horizontal: 5, vertical: 5),
        scrollDirection: Axis.horizontal,
        children: cateList.map((e) {
          return GestureDetector(
            child: cateItemWidget(e),
            onTap: () => NavRoute.pushTo(e.modulePath, context, param: e.params),
          );
        }).toList(),
      ),
    );
  }

  Widget cateItemWidget(HomeCategory cate) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 5),
      width: 84,
      height: 110,
      alignment: Alignment.center,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(7),
        boxShadow: [
          BoxShadow(
            color: Color.fromRGBO(240, 240, 240, 1),
            offset: Offset(1, 1),
          ),
          BoxShadow(
            color: Color.fromRGBO(240, 240, 240, 1),
            offset: Offset(-1, -1),
          ),
        ],
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          CachedNetworkImage(
            imageUrl: cate.moduleImageUrl,
            height: 32,
          ),
          Padding(
            padding: EdgeInsets.only(top: 10),
            child: Text(
              cate.moduleName,
              style: TextStyle(fontSize: 12),
            ),
          ),
        ],
      ),
    );
  }
}
